package com.windy.common.header;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created by liyufeng on 2022/5/8
 */
public class Headers {
    private List<Header> headers = Lists.newArrayList();

    public Headers add(Header header) {
        headers.add(header);
        return this;
    }

    public boolean contains(Header header){
       return headers.stream().anyMatch(context-> StrUtil.equals(context.key(),header.key()));
    }

    public boolean contains(String  key){
        if(CollectionUtil.isEmpty(headers)){
            return false;
        }
        return headers.stream().anyMatch(context-> StrUtil.equals(context.key(),key));
    }

    @Override
    public String toString() {
        return "Headers{" +
                "Headers=" + headers.toString() +
                '}';
    }
}
